package com.example.finalssm.Controller;

import com.example.finalssm.mapper.UserMapper;
import com.example.finalssm.utils.MybatisUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/blogger")
public class RegisterController {
    @RequestMapping("/register")
    public String register(@RequestParam("username") String username, @RequestParam("password") String password,
                           Model model) {
        if (username != null && password != null) {
            Map<String, String> map = new HashMap<>();
            map.put("username", username);
            map.put("password", password);
            int i = MybatisUtils.getSqlSession().getMapper(UserMapper.class).registerUser(map);
            if (i == 1) {
                model.addAttribute("msg", "注册成功");
            } else {
                model.addAttribute("msg", "注册失败");
            }
        }
        return "redirect:index.html";
    }
}
